#pragma once
#ifndef Game_GameEngine_Scene_h
#define Game_GameEngine_Scene_h

#include "DrawableEntity.h"
#include "ICollection.h"
#include "RTTI.h"
#include "../Common/Collection.h"

namespace Game {
namespace Common {

class EntityLogicManager;
class EntityLogicPair;
class EntityRenderPair;
class EntityRenderManager;
class SceneIterator;

class Scene : public DrawableEntity, public ICollection<Entity*> {
    RTTI_DECL;
public:
    friend SceneIterator;
    Scene();
    virtual ~Scene();
    virtual int GetCount();
    virtual void Add(Entity* item);
    virtual void Clear();
    virtual Entity* GetItem(int index);
    virtual int IndexOf(Entity* item);
    virtual bool Remove(Entity* item);
    virtual void RemoveAt(int index);
    EntityLogicManager* GetEntityLogicManager() const;
    void SetEntityLogicManager(EntityLogicManager* val);
    Collection<EntityLogicPair*>* GetEntityLogic() const;
    Collection<EntityRenderPair*>* GetEntityRender() const;
private:
    Collection<DrawableEntity*>* drawableGameEntities;
    Collection<Entity*>* gameEntities;
    Collection<EntityLogicPair*>* entityLogic;
    Collection<EntityRenderPair*>* entityRender;
    EntityLogicManager* gameLogicManager;
    void AddEntityLogic(Entity* item);
    void ClearEntityLogic();
    void RemoveEntityLogic(Entity* item);
};

class SceneIterator : public ICollectionIterator<Entity*> {
public:
    SceneIterator(Scene* scene) : scene(scene) {
        this->iterator = CollectionIterator<Entity*>(this->scene->gameEntities);
    }

    ~SceneIterator() {
    }

    virtual void operator++() {
        this->iterator++;
    }

    virtual void operator ++(int) {
        this->iterator++;
    }

    virtual bool operator()() {
        return this->iterator();
    }

    virtual Entity* operator *() {
        return *this->iterator;
    }
private:
    Scene* scene;
    CollectionIterator<Entity*> iterator;
};

}
}

#endif
